package com.tongfusoft.document.web.controller.index;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.tongfusoft.document.entity.Users;
import com.tongfusoft.spring.web.core.data.ResultModel;
import com.tongfusoft.utils.Constant;
@Controller
public class IndexController {

	
	@RequestMapping("/login")
	public String login(Model model){
		
		return "login";
	}
	@RequestMapping("/currUser")
	@ResponseBody
	public ResultModel currUser(HttpSession session){
		ResultModel rm = new ResultModel();
		
	try {
		Users user = (Users) session.getAttribute(Constant.SESSION_USER);
		rm.setData(user);
		rm.setState("success");
		
	} catch (Exception e) {
		rm.setState("error");
		e.printStackTrace();
	}
		return rm;
	}
	@RequestMapping("/")
	public String test(HttpServletRequest request, Model model) {

		model.addAttribute("mainPageKey", "index");
		model.addAttribute("mainPage", "index");

		return "base";
	}
}
